home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.object,comp.lang.c++,comp.lang.java
- Path: ERA.COM!era!spencer
- From: spencer@ERA.COM (Spencer Allain)
- Subject: Re: Java: What's the Big Deal?
- In-Reply-To: shang@corp.mot.com's message of Mon, 1 Apr 1996 15: 54:16 GMT
- Message-ID: <SPENCER.96Apr1132420@zorgon.ERA.COM>
- Sender: news@ERA.COM
- Organization: Engineering Research Associates, Vienna, VA
- References: <4jk4ee$7ri@newsbf02.news.aol.com>
- <1996Apr1.155416.12816@schbbs.mot.com>
- Date: Mon, 1 Apr 1996 17:24:20 GMT
-
- In article <1996Apr1.155416.12816@schbbs.mot.com> shang@corp.mot.com (David L. Shang) writes:
-
- The more a program depends on GC, the more likely it will exhaust memory;
- because the storage is collected only when all its references are
- no longer valid, not at the time when all its references are no longer
- used. Be careful, never make a variable's lifetime unecessarily longer
- than the required.
-
- Uhh, this isn't necessarily true. By doing your own memory management in
- programs where large structures are passed around (and it's abiguous as
- to who is responsible for their deletion) memory often stays allocated
- longer than it needs and you often require some type of home-grown
- reference counting mechanism. Of course if you don't work on applications
- that deal with large structures and/or complex control flows of data then
- you will generally exhaust memory less often than with garbage collection
- since you "know" exactly when something should be deleted. The more
- complex the application, it often can become the case that the use of
- garbage collection will _reduce_ your memory requirements, since it
- already has optimized the memory management that you have to kludge
- together when it isn't available.
-
- The more a language depends on GC, the more likely its application will
- exhaust memory, or at the best, will make the operating system busy
- to crunch the memory. GC is not always required. For example:
-
- class point
- {
- public:
- float x;
- float y;
- float z;
- };
- class FaceSet
- {
- coordIndex point[];
- ...
- public:
- loadCoordIndex (char* file_name)
- {
- one million of points read here, and
- coordIndex is created as an array of
- a million of points.
- };
- };
-
- With Java's array, memory will be smashed into millions of small
- pieces. Here is a brief comparison:
-
- Java not having a contiguous array structure, has nothing to do with
- garbage collection in general. Also, the C++ "array" that is
- being compared against, is the C-style "array" (a pointer to a
- contiguous block of memory); it doesn't abstract to multidimensional
- arrays, which are more efficiently handled in langauges with real
- arrays.
-
- Java array C++ array
-
- pieces: 1,000,000 pieces 1 piece
-
- expence: 1,000,000 type refs + 3,000,000 floats
- 1,000,000 obj refs +
- 1,000,000 gc overheads +
- 3,000,000 floats
-
- allocation: 1,000,001 times 1 time
-
- free time: 1,000,001 times 1 time
-
-
- BTW, is this really how Java does all of its arrays? If so, this
- will lead to painful conclusions such as the above comparison.
-
- Oh well, I have garbage collection, and real arrays, so I'm happy
- either way. :-)
-
- -Spencer
-
- ----------------------------------------------------------------------
- Spencer Allain E-mail: spencer@era.com
- Engineering Research Associates Phone : (703) 734-8800 x1414
- 1595 Spring Hill Road Fax : (703) 827-9411
- Vienna, VA 22182-2235
-
- <A HREF=http://www.research.digital.com/SRC/modula-3/html/home.html>
- Modula-3 Home Page DEC SRC</A>
- <A HREF=http://www.vlsi.polymtl.ca/m3/>Modula-3 FAQ, etc. </A>
- ----------------------------------------------------------------------
-